package com.flx.noodle.websocket.service;

import com.flx.noodle.websocket.dao.RoomDao;
import com.flx.noodle.websocket.entity.ChatRoom;
import com.flx.noodle.websocket.searcher.RoomSearcher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by fenglixiong on 2017/10/2.
 */
@Service
public class RoomService {

    @Autowired
    private RoomDao roomDao;

    public ChatRoom getRoomById(int roomId){
        return roomDao.getRoomById(roomId);
    }

    public int saveOrUpdate(ChatRoom chatRoom){
        if(chatRoom.getChatId()==null){
            return insertRoom(chatRoom);
        }else {
            return updateRoom(chatRoom);
        }
    }

    public int insertRoom(ChatRoom chatRoom){
        return roomDao.insertRoom(chatRoom);
    }

    public int updateRoom(ChatRoom chatRoom){
        return roomDao.updateRoom(chatRoom);
    }

    public int deleteRoom(int roomId){
        return roomDao.deleteRoom(roomId);
    }

    public List<ChatRoom> findRoomList(RoomSearcher searcher){
        return roomDao.findRoomList(searcher);
    }


}
